home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tclsrc / forrecur.tcl < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.2 KB  |  33 lines

  1. #
  2. # forrecur.tcl --
  3. #
  4. # Proc to execute code on every file in a recursive directory glob.
  5. #------------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: forrecur.tcl,v 2.0 1992/10/16 04:52:00 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. #@package: TclX-forrecur for_recursive_glob
  20.  
  21. proc for_recursive_glob {var globlist code {depth 1}} {
  22.     upvar $depth $var myVar
  23.     foreach globpat $globlist {
  24.         foreach file [glob -nocomplain $globpat] {
  25.             if [file isdirectory $file] {
  26.                 for_recursive_glob $var $file/* $code [expr {$depth + 1}]
  27.         }
  28.         set myVar $file
  29.         uplevel $depth $code
  30.         }
  31.     }
  32. }
  33.